package util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class InputOutputStreamConnector<I extends InputStream, O extends OutputStream> {
	
	private static final int BYTE_BUFFER_SIZE = 1024;
	
	I in;
	O out;
	byte buffer[];
	
	public InputOutputStreamConnector(I in, O out) {
		this.in = in;
		this.out = out;
		buffer = new byte[BYTE_BUFFER_SIZE];
	}
	
	public void setInputStream (I in) {
		this.in = in;
	}
	
	public void setOutputStream (O out) {
		this.out = out;
	}
	
	public I getInputStream() {
		return in;
	}
	
	public O getOutputStream() {
		return out;
	}
	
	public void go() throws IOException {
			
		int readLength;
		while ( (readLength = in.read(buffer)) != -1 );
		out.write(buffer, 0, readLength);
			
	}
}
